<?php
class Epic_Db_ObjectWatcher 
{
	private $all = array();
	/**
     * Singleton instance
     * @var Epic_Db_ObjectWatcher
     */
	private static $_instance = null;
	
	private function __construct() {}
	
	/**
	 * Singleton instance
	 *
	 * @return Epic_Controller_Front
	 */
	public static function getInstance()
	{
		if (null === self::$_instance) {
			self::$_instance = new self();
		}
		return self::$_instance;
	}
	
	function globalKey(Epic_Db_Model_Object $obj, $nameTable) 
	{
		$key = $nameTable . "." . $obj->getId();
		return $key;
	}
	
	static function add(Epic_Db_Model_Object $obj, $nameTable)
	{
		$inst = self::getInstance();
		$inst->all[$inst->globalKey($obj, $nameTable)] = $obj;
	}
	
	static function exists($nameTable, $id) 
	{
		$inst = self::getInstance();
		$key = "$nameTable.$id";
		if(isset($inst->all[$key])) {
			return $inst->all[$key];
		}
		return null;
	}
}